<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改培训计划')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<link th:href="@{/ajax/libs/bootstrap-fileinput/fileinput.min.css}" rel="stylesheet" />
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-plan-edit" enctype="multipart/form-data" th:object="${trainingPlan}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="img" th:field="*{img}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">计划编号：</label>
                <div class="col-sm-8">
                    <input name="planId" th:field="*{planId}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group" style="width: 50%;margin-left: 26%;">
                <!--<label class="col-sm-3 control-label">图片：</label>-->
                <div class="file-loading">
                    <input id="image" name="image" type="file" multiple required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">培训名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">培训分类：</label>
                <div class="col-sm-8">
                   <!-- <select name="type" class="form-control m-b">
                        <option value="">所有</option>
                    </select>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
                    <select name="type" th:with="type=${@dict.getType('t_hr_training_plan')}" class="form-control m-b" required>
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">负责人：</label>
                <div class="col-sm-8">
                    <input name="principal" th:field="*{principal}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">培训说明：</label>
                <div class="col-sm-8">
                    <textarea name="trainingExplain" class="form-control" required>[[*{trainingExplain}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">发布时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="releaseTime" th:value="${#dates.format(trainingPlan.releaseTime, 'yyyy-MM-dd')}" readonly="readonly" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">培训计划：</label>
                <div class="col-sm-8">
                    <textarea name="plan" class="form-control" required>[[*{plan}]]</textarea>
                </div>
            </div>
           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">创建者id：</label>
                <div class="col-sm-8">
                    <input name="createId" th:field="*{createId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">更新者id：</label>
                <div class="col-sm-8">
                    <input name="updateId" th:field="*{updateId}" class="form-control" type="text">
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script src="/ajax/libs/bootstrap-fileinput/fileinput.min.js" th:src="@{/ajax/libs/bootstrap-fileinput/fileinput.min.js}">
    </script>
    <script type="text/javascript">
        var prefix = ctx + "hr/training/plan";
        $("#form-plan-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = new FormData();
                data.append("id",$("input[name=id]").val());
                data.append("planId",$("input[name=planId]").val());
                data.append("releaseTime",$("input[name=releaseTime]").val());
                data.append("name",$("input[name=name]").val());
                data.append("type",$("select[name=type]").val());
                data.append("principal",$("input[name=principal]").val());
                data.append("trainingExplain",$("textarea[name=trainingExplain]").val());
                data.append("plan",$("textarea[name=plan]").val());
                data.append("image", document.getElementById('image').files[0]);

                $.ajax({
                    type: "POST",
                    url: prefix + "/edit",
                    data: data,
                    processData: false, //因为data值是FormData对象，不需要对数据做处理。
                    contentType: false,
                    success: function(result) {
                        $.operate.successCallback(result);
                        // console.log(result)
                    }

                });
            }
        }

        $("input[name='releaseTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(document).ready(function () {
            $("#image").fileinput({
                'theme': 'explorer-fas',
                allowedFileExtensions: ["jpg", "JPG", "jpeg", "JPEG", "png", "gif"],
                uploadUrl: prefix+'/uploadImg/'+'[[${id}]]',
                allowedFileExtensions: ["jpg", "JPG", "jpeg", "JPEG", "png", "gif"],
                autoReplace: true,//自动替换上一个文件
                removeFromPreviewOnError:true, //当选择的文件不符合规则时，例如不是指定后缀文件、大小超出配置等，选择的文件不会出现在预览框中，只会显示错误信息
                showUpload:false,//不展示上传按钮 体验不好 需要用户自己点击
                showCaption: false,    //不显示标题
                layoutTemplates:{
                    actionUpload:'',//去除上传预览缩略图中的上传图片
                },
                maxFileCount:1,
                dropZoneEnabled: false,//不显示拖拽上传区域
                dropZoneTitle:'拖拽文件到这里 &hellip;<br>',
                initialPreview:[
                    "[[${trainingPlan.img}]]"
                ],
                initialPreviewAsData: true,

            });
        });
    </script>
</body>
</html>